package com.hopebridge.demo.wxsy.web.controller;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.hopebridge.demo.wxsy.service.IndexService;

@Controller
public class IndexController {
	
	@Autowired
	@Qualifier(value="indexService")
	private IndexService indexService;
	
	@RequestMapping("index")
	public String index(){
		return "/index";
	}

	@RequestMapping(value="welcomePage")
	public ModelAndView welcomePage(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException{
		request.setCharacterEncoding("utf-8");
		String userName = request.getParameter("userName");
		request.setAttribute("userName", userName);
		ModelAndView mv = new ModelAndView("/welcome");
		mv.addObject("userName", userName);
		mv.addObject("welcome", indexService.generateHello(userName));
		return mv;
	}
}
